<?php

class Support_Model extends CI_Model {
	
	function Support_Model() {
		parent::__construct ();
		$this->load->database ();
	}
	
	function get($id = FALSE) {
		if ($id === FALSE) {
			$query = $this->db->get ( 'support' );
			if ($query->num_rows () <= 0) {
				return FALSE;
			}
			return $query->result_array ();
		} else {
			$query = $this->db->get_where ( 'support', array ('id' => $id ) );
			if ($query->num_rows () <= 0) {
				return FALSE;
			}
			return $query->row_array ();
		}
	}
	
	function add($data) {
		foreach ( $data as &$d ) {
			$d = $this->db->escape_str ( $d );
		}
		if (! $this->db->insert ( 'support', $data ))
			return FALSE;
		else {
			return $this->db->insert_id ();
		}
	}
	
	function get_by_type($type) {
		$query = $this->db->get_where ( 'support', array ('type' => $type ) );
		if($query->num_rows() <= 0){
			return FALSE;
		}
//		$content = in_array($needle, $haystack)
		$array = $query->row_array();
		return explode(',', $array['content']);
	}
	
	function delete($id) {
		$this->db->where ( 'id', $id );
		$query = $this->db->delete ( 'support' );
		if (! $query)
			return false;
		else
			return true;
	}
	
	/* Function: Update
     * Author: Chung HD
     * Date: 27/09/2011
     */
	
	function update($id, $data) {
		foreach ( $data as &$d ) {
			$d = $this->db->escape_str ( $d );
		}
		
		if (isset ( $data ['type'] ))
			$newdata ['type'] = $data ['type'];
		if (isset ( $data ['content'] ))
			$newdata ['content'] = $data ['content'];
		$this->db->where ( 'id', $id );
		$query = $this->db->get ( 'support' );
		if ($query->num_rows () == 0)
			return false;
		else {
			$this->db->where ( 'id', $id );
			if ($this->db->update ( 'support', $newdata ))
				return true;
			else
				return false;
		}
	}
	
/*
     * Function: searchcardByLetter($letter)
     * Author: Chung Hd
     * Date: 28/09/2011
     */
}

?>